package com.yxw.yxnet_cd_center.customer_service.controller;

import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.customer_service.dto.CustomOperateDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.CustomOperateQueryDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.ProductQueryDTO;
import com.yxw.yxnet_cd_center.customer_service.entity.YxCsPushProductEntity;
import com.yxw.yxnet_cd_center.customer_service.service.ICustomOperateService;
import com.yxw.yxnet_cd_center.customer_service.vo.CustomOperateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户运营Controller控制层处理
 *
 * @author xiexuxin
 * @date 2023-09-24
 */

@Slf4j
@Api(value = "客户运营", tags = "客户运营")
@RestController
@Validated
@RequestMapping("/v1/custom-operate")
public class CustomOperateController {

    @Autowired
    private ICustomOperateService operateService;

    /**
     * 添加运营项目
     */
    @ApiOperation("添加运营项目")
    @PostMapping("/addCustomOperate")
    public BaseResult addCustomOperate(@RequestBody CustomOperateDTO operateDTO) {
        operateService.addCustomOperate(operateDTO);
        return BaseResult.success();
    }

    /**
     * 查询客户
     */
    @ApiOperation("查询客户")
    @PostMapping("/cust-list")
    public BaseResult listCustomers(@RequestParam(name = "tagIds", required = false) List<Long> tagIds) {
        if (tagIds != null && !tagIds.isEmpty()) {
            return BaseResult.success(operateService.findByCustTagId(tagIds));
        } else {
            return BaseResult.success(operateService.findAll());
        }
    }

    /**
     * 删除运营项目
     */
    @ApiOperation("根据id删除运营项目数据")
    @PostMapping("/{operateId}/deleteByOperateId")
    public BaseResult remove(@PathVariable Long operateId) {
        log.info("开始处理【根据id删除运营项目数据】的请求，参数：{}", operateId);
        operateService.deleteByOperateId(operateId);
        return BaseResult.success();
    }

    /**
     * 批量删除运营项目
     */
    @ApiOperation("根据id批量删除运营项目数据")
    @PostMapping("/{operateIds}/batch-delete")
    public BaseResult batchDelete(@PathVariable List<Long> operateIds) {
        log.info("开始处理【根据id批量删除运营项目数据】的请求，参数：{}", operateIds);
        operateService.deleteByOperateIds(operateIds);
        return BaseResult.success();
    }

    /**
     * 修改运营项目
     */
    @ApiOperation("根据id修改运营项目数据")
    @PostMapping("{operateId}/updateOperate")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "operateId", value = "运营ID", required = true, dataType = "long")
    })
    public BaseResult edit( @PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long operateId,
                            @RequestBody CustomOperateDTO operateDTO) {
        log.info("开始处理【根据id修改运营项目数据】的请求，ID：{}，新数据：{}", operateId,operateDTO);
        operateService.updateOperate(operateId,operateDTO);
        return BaseResult.success();
    }

    /**
     * 根据id查询运营项目数据信息
     */
    @ApiOperation(value = "根据id查询运营项目数据信息")
    @GetMapping(value = "/{operateId}")
    public BaseResult getInfo(@PathVariable("operateId") Long operateId) {
        log.info("开始处理【根据id查询运营项目数据信息】的请求，ID：{}", operateId);
        CustomOperateVO operateVO = operateService.selectOperateById(operateId);
        return BaseResult.success(operateVO);
    }

    /**
     * 查询问题列表
     */
    @ApiOperation(value = "查询运营项目数据列表")
    @PostMapping("/operateList")
    public BaseResult operateList() {
        log.info("开始处理【查询运营项目数据列表】请求,无参数");
        List<CustomOperateVO> list = operateService.operateList();
        return BaseResult.success(list);
    }

    /**
     *条件查询问题列表
     */
    @ApiOperation(value = "条件查询运营项目数据")
    @PostMapping(value = "/getCprList")
    public BaseResult<PageVO<CustomOperateVO>> getCprList(@RequestBody CustomOperateQueryDTO operateDTO) {
        log.info("开始处理【条件查询运营项目数据】请求,参数:{}",operateDTO);
        PageVO<CustomOperateVO> pageVo=operateService.getOperateList(operateDTO);
        return ResultHelper.fillWithSuccess(pageVo);
    }

    /**
     * 查询商品列表
     */
    @ApiOperation(value = "查询商品列表")
    @PostMapping(value = "/productList")
    public BaseResult getProductList() {
        log.info("开始处理【查询商品列表】请求,无参数");
        List<YxCsPushProductEntity>  productList = operateService.productList();
        return BaseResult.success(productList);
    }

    /**
     * 条件查询商品列表
     */
    @ApiOperation(value = "条件查询商品列表")
    @PostMapping(value = "/getProductList")
    public BaseResult getProductList(@RequestBody ProductQueryDTO productQueryDTO) {
        log.info("开始处理【条件查询商品列表】请求,参数:{}",productQueryDTO);
        List<YxCsPushProductEntity> productList=operateService.getProductList(productQueryDTO);
        return ResultHelper.fillWithSuccess(productList);
    }

    /**
     * 点击发送修改运营状态
     */
    @ApiOperation(value = "点击发送修改运营状态")
    @PostMapping(value = "/updateStatus")
    public BaseResult updateStatus(Long operateId, Long operateStatus) {
        log.info("开始处理【点击发送修改运营状态】请求,无参数");
        operateService.updateStatus(operateId, operateStatus);
        return BaseResult.success();
    }

}
